<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加题目</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<%=basePath%>/layui/css/layui.css" media="all">
  <script src="<%=basePath%>/js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath%>/js/vue.min.js"></script>
	<script src="<%=basePath%>/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<form class="layui-form">
	<div class="layui-form-item" style="margin-top:50px;">
	    <div class="layui-form-item">
		    <label class="layui-form-label">项目名称：</label>
		    <div class="layui-input-inline">
			    <input class="layui-input" style="width:300px;" type = "text" id="sbjName" lay-verify="required" lay-reqtext="账号是必填项！">
			</div>
		</div>
	    <div class="layui-form-item">
		    <label class="layui-form-label">项目内容：</label>
		    <div class="layui-input-inline">
                <textarea class="layui-textarea"  style="width:600px;height:300px" id="sbjContent"></textarea>
			    <!-- <input  class="layui-input" style="width:300px;" type = "text" id="sname" lay-verify="required" lay-reqtext="用户名是必填项！"> -->
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">题目类型：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="sbjType">
			</div>
		</div>
		<div class="layui-form-item">
		    <label class="layui-form-label">适合专业：</label>
		    <div class="layui-input-inline">
			    <input  class="layui-input" style="width:300px;" type = "text" id="sbjMajor">
			</div>
		</div>
	    <div class="layui-form-item" style="margin-left:150px;margin-top:50px;">
			<button type="button" class="layui-btn" lay-submit="" lay-filter="add">添加</button>
			<button type="button" class="layui-btn" onclick="back();">返回</button>
		</div>
 	 </div>
</form>
</body>

<script>

layui.use(['form', 'layedit', 'laydate'], function(){
	var form = layui.form
	,layer = layui.layer
	,layedit = layui.layedit
	,laydate = layui.laydate;

	form.on('submit(add)', function(data){
		var param = new Object();
		param.sbjName  = $('#sbjName').val();
		param.sbjContent = $('#sbjContent').val();
		param.sbjType = $('#sbjType').val();
		param.sbjMajor = $('#sbjMajor').val();
		//全部更新 解决单选框不渲染
		form.render();
		
		 console.log("send message:"+JSON.stringify(param));
		 $.ajax({
				type:"GET",
				url:"/bysjxksys/teacher/add_sbj",
				dataType:"json",
				//contentType:"application/json",
		        data:param,
				success: function(data){
					if(data.code==1){
						alert(data.msg);
					}else{
						alert("添加题目成功！");
						parent.location.reload();				
					}
				},
				error: function(data, type, err){
					console.log(type);
					console.log(err);
				}
			});
		
	    return false;
	});
});

function back(){
	//当你在iframe页面关闭自身时
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
    window.location.reload();
};

</script>
</html>